package com.bw.liuyushan.liuyushan20210929.MVP.Model;

import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.liuyushan20210929.Entity.JsonBean;
import com.bw.liuyushan.liuyushan20210929.Entity.UserBean;
import com.bw.liuyushan.liuyushan20210929.MVP.Contrack.IContrackTest;
import com.bw.liuyushan.liuyushan20210929.Requestaddress.API_Food;
import com.bw.liuyushan.liuyushan20210929.Requestaddress.API_User;
import com.bw.liuyushan.liuyushan20210929.Utils.RxJavaFoodManager;
import com.bw.liuyushan.liuyushan20210929.Utils.RxJavaLoginManager;
import com.bw.liuyushan.mvp_lib.Model.BaseModel;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Liuyushan20210929
 * file name is : BaseModelTest
 * created by Ender on 2021/9/29 13:49.
 * author : 刘雨杉
 * Describe:
 */
public class BaseModelTest extends BaseModel implements IContrackTest.C_ModelTest {
    @Override
    public void askLogin(String username, String password, Observer<UserBean> observer) {
        if (NetworkUtils.isAvailableByPing()){//网络判断 判断网络是否连接
            RxJavaLoginManager.getInstance().getRetrofit().create(API_User.class)
                    .TestLogin(username, password)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(observer);
        }else{
            ToastUtils.showShort("网络未连接");
        }

    }

    @Override
    public void askReg(String username, String password, String repassword, Observer<UserBean> observer) {
        if (NetworkUtils.isAvailableByPing()){//网络判断 判断网络是否连接
            RxJavaLoginManager.getInstance().getRetrofit().create(API_User.class)
                    .TestReg(username, password, repassword)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(observer);
        }else{
            ToastUtils.showShort("网络未连接");
        }
    }

    @Override
    public void askDate(String url, Observer<JsonBean> observer) {
        if (NetworkUtils.isAvailableByPing()){//网络判断 判断网络是否连接
        RxJavaFoodManager.getInstance().getRetrofit().create(API_Food.class)
                .TestFood(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
        }else{
            ToastUtils.showShort("网络未连接");
        }
    }
}
